
local Shangdan = fk.CreateSkill {
    name = "Shangdan",
}


Fk:loadTranslationTable{
    ["Shangdan"] = "商单",
    [":Shangdan"] = "每回合限三次，当你不以此法获得手牌前，你可改为从牌堆中随机获得一张【桃】或【无中生有】。",
    ["#ShangdanChoice"] = "商单：请选择获得【桃】或【无中生有】",
  } 

Shangdan:addEffect(fk.BeforeCardsMove, {
  
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(Shangdan.name) then
        for _, move in ipairs(data) do
            if move.to == player and move.toArea == Card.PlayerHand and move.skillName ~= Shangdan.name then
              return player:usedSkillTimes(Shangdan.name, Player.HistoryTurn) < 3
            end
        end
    end

  end,
  
  on_cost = function(self, event, target, player, data)
    local choice = player.room:askToChoice(player, {
      choices = {"Cancel","peach", "ex_nihilo"},
      skill_name = Shangdan.name,
      prompt = "#ShangdanChoice",
    })
    if choice ~= "Cancel" then
      event:setCostData(self, {choice = choice} )
      return true
    end
  end,
  
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, move in ipairs(data) do
      if move.to == player and move.toArea == Card.PlayerHand and move.skillName ~= Shangdan.name then
        for i = #move.moveInfo, 1, -1 do
          local info = move.moveInfo[i]
            table.removeOne(move.moveInfo, info)
           -- break
          end
      end
    end
    local cards = table.filter(room.draw_pile, function(id)
      return Fk:getCardById(id).name == event:getCostData(self).choice
    end)
    if #cards > 0 then
      local card = Fk:getCardById(table.random(cards))
      room:obtainCard(player,card,false,fk.ReasonPrey,player,Shangdan.name)
    end
  end
})


return Shangdan 